clear textprogressbar; clear; clc;
%% Create session, Connect devices
PROJ_PATH = [current_file_path(mfilename('fullpath') ) '\'];
session=MeasurementSession.SimpleMeasurement('owner',       'ZN', ...
                                             'name',        'TestSpectrum',...
                                             'device_file', [PROJ_PATH 'device.dat'] );
                                         
session.addDescription( ...
    ['This Measurement tests the batch operation of Spectrum Module.' ...
     'Device infomation should be provide in ''device.dat''. '  ...
     'Module settings should be provide in ''settings.mat''. ' ] ...
    );
%% Spectrum Settings
zi = session.getDevice('dev3546');

scope = zi.scopeModule(session);
%%
scope.enableChannel('both');
scope.inputSelect('0', 0);
scope.inputSelect('1', 12);

scope.enableTrigger();
scope.setTriggerChannel(10);
scope.setMode('time');
% scope.setMode('frequency');

% % Specify the trigger channel, we choose the same as the scope input
% ziDAQ('setInt',    ['/' device '/scopes/0/trigchannel'], str2double(in_c));
% % Trigger on rising edge?
% ziDAQ('setInt',    ['/' device '/scopes/0/trigrising'], 1);
% % Trigger on falling edge?
% ziDAQ('setInt',    ['/' device '/scopes/0/trigfalling'], 0);
% % Set the trigger threshold level
% ziDAQ('setDouble', ['/' device '/scopes/0/triglevel'], 0.00);
% % Set hysteresis triggering threshold to avocid triggering on noise
% % 'trighysteresis/mode' :
% %  0 - absolute, use an absolute value ('trighysteresis/absolute')
% %  1 - relative, use a relative value (trighysteresis/relative') of the trigchannel's input range
% ziDAQ('setDouble',    ['/' device '/scopes/0/trighysteresis/mode'], 1);
% ziDAQ('setDouble',    ['/' device '/scopes/0/trighysteresis/relative'], 0.1); % 0.1=10%
% 
% % Set the hold off time inbetween triggers
% ziDAQ('setDouble',    ['/' device '/scopes/0/trigholdoff'], 0.025);
% 
% % Set trigdelay to 0.: Start recording from when the trigger is activated.
% ziDAQ('setDouble',    ['/' device '/scopes/0/trigdelay'], 0.0);



scope.subscribeChannel();
res=scope.run();
scope.unsubscribeChannel();
% [res, dataAll]=scope.runAverage(10);
% 
% figure;
% semilogy(res)